
#include "../inc/Page.h"
#include <assert.h>


	ostream &operator<<(ostream &stream, Page *o){
		      stream << o->getURL();
		      return stream;
	}

	Page::Page(URL &page, string &text, LinkedList<URL> &addresses){
		url=new URL(page);
		description = new string(text);
		links = new LinkedList<URL>(addresses);
	}

//Constructor used for making pages that will be used for searching the tree
	Page::Page(URL &page){	
			url=new URL(page);
			description = NULL;
			links = NULL;
		}

	Page::Page(const Page &other){
		url = new URL(*(other.url));
		description = new string(*(other.description));
		links = new LinkedList<URL>(*(other.links));
	}

	Page& Page::operator =(const Page &other){
		assert(other.description!=NULL && other.links!=NULL);
		if(this!=&other){
			delete url;
			delete description;
			delete links;
			url = new URL(*(other.url));
			description = new string(*(other.description));
			links = new LinkedList<URL>(*(other.links));
		}
		return *this;
	}

	Page::~Page(){
		delete url;
		delete description;
		delete links;
	}

	string Page::getDescription(){
		assert(description!=NULL);
		return *description;
	}

	LinkedList<URL> Page::getLinks(){
		assert(links!=NULL);
		return *links;
	}

	URL Page::getURL(){
		assert(url!=NULL);
		return *url;
	}

	int Page::compare(Page &other){
		assert(url!=NULL && other.url!=NULL);
		return url->compare(*(other.url));
	}

//	operator Page::Occurrence(){
//	   	return Occurrence(this);
//	}


	string Page::print(){
		string temp;
		temp += url->getAddress();
		temp += " ";
		temp += *description;
		return temp;
	}
